PEP 746 – Type checking Annotated metadata | 您所在的位置:网站首页 › python annotated › PEP 746 – Type checking Annotated metadata |
PEP 746 – Type checking Annotated metadata
Author:
Adrian Garcia Badaracco
Sponsor:
Jelle Zijlstra
Discussions-To:
Discourse thread
Status:
Draft
Type:
Standards Track
Topic:
Typing
Created:
20-May-2024
Python-Version:
3.14
Post-History:
20-May-2024
Table of Contents
Abstract
Motivation
Specification
Backwards Compatibility
Security Implications
How to Teach This
Reference Implementation
Rejected ideas
Introducing a type variable instead of a generic class
Introducing a new type to typing.py that all metadata objects should subclass
Acknowledgments
Copyright
Abstract
This PEP proposes a mechanism for type checking metadata that uses the typing.Annotated type. Metadata objects that implement the new __supports_type__ protocol will be type checked by static type checkers to ensure that the metadata is valid for the given type. MotivationPEP 593 introduced Annotated as a way to attach runtime metadata to types. In general, the metadata is not meant for static type checkers, but even so, it is often useful to be able to check that the metadata makes sense for the given type. Take the first example in PEP 593, which uses Annotated to attach serialization information to a field: class Student(struct2.Packed): name: Annotated[str, struct2.ctype(" |
CopyRight 2018-2019 实验室设备网 版权所有 |